/// 万年历信息模型 - Calendar information model
class CalendarInfo {
  /// 农历日期 - Lunar date
  final String lunarDate;
  
  /// 星座 - Constellation
  final String constellation;
  
  /// 生肖 - Zodiac
  final String zodiac;
  
  /// 干支 - Ganzhi (Heavenly Stems and Earthly Branches)
  final String ganzhi;
  
  /// 节气 - Solar term
  final String solarTerm;
  
  /// 公历节日 - Solar festivals
  final List<String> festivals;
  
  /// 农历节日 - Lunar festivals
  final List<String> lunarFestivals;
  
  /// 宜 - Suitable activities
  final List<String> yi;
  
  /// 忌 - Unsuitable activities
  final List<String> ji;
  
  /// 五行 - Five elements
  final String fiveElements;
  
  /// 纳音 - Nayin
  final String nayin;

  const CalendarInfo({
    required this.lunarDate,
    required this.constellation,
    required this.zodiac,
    required this.ganzhi,
    required this.solarTerm,
    required this.festivals,
    required this.lunarFestivals,
    required this.yi,
    required this.ji,
    required this.fiveElements,
    required this.nayin,
  });

  /// 从JSON创建CalendarInfo实例 - Create CalendarInfo instance from JSON
  factory CalendarInfo.fromJson(Map<String, dynamic> json) {
    return CalendarInfo(
      lunarDate: json['lunar_date'] ?? '',
      constellation: json['constellation'] ?? '',
      zodiac: json['zodiac'] ?? '',
      ganzhi: json['ganzhi'] ?? '',
      solarTerm: json['solar_term'] ?? '',
      festivals: List<String>.from(json['festivals'] ?? []),
      lunarFestivals: List<String>.from(json['lunar_festivals'] ?? []),
      yi: List<String>.from(json['yi'] ?? []),
      ji: List<String>.from(json['ji'] ?? []),
      fiveElements: json['five_elements'] ?? '',
      nayin: json['nayin'] ?? '',
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'lunar_date': lunarDate,
      'constellation': constellation,
      'zodiac': zodiac,
      'ganzhi': ganzhi,
      'solar_term': solarTerm,
      'festivals': festivals,
      'lunar_festivals': lunarFestivals,
      'yi': yi,
      'ji': ji,
      'five_elements': fiveElements,
      'nayin': nayin,
    };
  }

  /// 创建默认实例 - Create default instance
  factory CalendarInfo.defaultInstance() {
    return const CalendarInfo(
      lunarDate: '腊月初八',
      constellation: '摩羯座',
      zodiac: '鼠',
      ganzhi: '甲子年 丙子月 戊子日',
      solarTerm: '',
      festivals: [],
      lunarFestivals: [],
      yi: ['祈福', '出行', '会友', '学习'],
      ji: ['动土', '开仓', '搬家'],
      fiveElements: '木',
      nayin: '海中金',
    );
  }
}

/// 月份万年历数据模型 - Month calendar data model
class MonthCalendarData {
  /// 年份 - Year
  final int year;
  
  /// 月份 - Month
  final int month;
  
  /// 日期数据列表 - List of date data
  final List<DayCalendarData> days;

  const MonthCalendarData({
    required this.year,
    required this.month,
    required this.days,
  });

  /// 从JSON创建MonthCalendarData实例 - Create MonthCalendarData instance from JSON
  factory MonthCalendarData.fromJson(Map<String, dynamic> json) {
    return MonthCalendarData(
      year: json['year'] ?? DateTime.now().year,
      month: json['month'] ?? DateTime.now().month,
      days: (json['days'] as List<dynamic>?)
          ?.map((day) => DayCalendarData.fromJson(day as Map<String, dynamic>))
          .toList() ?? [],
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'year': year,
      'month': month,
      'days': days.map((day) => day.toJson()).toList(),
    };
  }
}

/// 日期万年历数据模型 - Day calendar data model
class DayCalendarData {
  /// 日期 - Date
  final int day;
  
  /// 万年历信息 - Calendar information
  final CalendarInfo calendarInfo;
  
  /// 是否为今天 - Whether it's today
  final bool isToday;
  
  /// 是否为节日 - Whether it's a festival
  final bool isFestival;

  const DayCalendarData({
    required this.day,
    required this.calendarInfo,
    this.isToday = false,
    this.isFestival = false,
  });

  /// 从JSON创建DayCalendarData实例 - Create DayCalendarData instance from JSON
  factory DayCalendarData.fromJson(Map<String, dynamic> json) {
    return DayCalendarData(
      day: json['day'] ?? 1,
      calendarInfo: CalendarInfo.fromJson(json['calendar_info'] ?? {}),
      isToday: json['is_today'] ?? false,
      isFestival: json['is_festival'] ?? false,
    );
  }

  /// 转换为JSON - Convert to JSON
  Map<String, dynamic> toJson() {
    return {
      'day': day,
      'calendar_info': calendarInfo.toJson(),
      'is_today': isToday,
      'is_festival': isFestival,
    };
  }
}